import wepy from 'wepy';
import tip from './tip'

const wxRequest = async(params = {}, url) => {
  tip.loading();
  let data = params.query || {};
  let res = await wepy.request({
    url: url,
    method: params.method || 'GET',
    data: data,
    header: {
      'Content-Type': 'application/json',
      'Authorization' : 'Bearer '+ wepy.$instance.globalData.token,
    }
  })
  tip.loaded();
  return res;
}

const wxUpload = async(file, url) => {
  tip.loading();
  let res = await wepy.uploadFile({
    url: url,
    name: 'file',
    filePath:file,
    header: {
      'Authorization' : 'Bearer '+ wepy.$instance.globalData.token,
    }
  })
  tip.loaded();
  return res;
}

module.exports = {
  wxRequest,
  wxUpload
}
